package ZZ_backup;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Properties;

import LawsonTransformJava.dao.DAOFactoryOracleDB;


public class PR560RecType3ACD extends DAObject implements DAOEmpAchDist {

	public PR560RecType3ACD() {
	    // initialization 
			try {
				// There is no separate output file for EmpAchDists.
				// It is assigned to an appropriate PayMastr record.
				this.output = null;
				init();
			} catch (ClassNotFoundException e) {
			    // Could not find the database driver
				System.out.println("ClassNotFoundException: " + e);
			} catch (SQLException e) {
			    // Could not connect to the database
				System.out.println("SQLException: " + e);
			} catch (IOException e) {
				// Could no write properties file
				System.out.println("IOException: " + e);
			}
	}
	
	@Override
	public TblEmpAchDist findEmployee(int company, String employeeNumber, long check_id) {
	  	TblEmpAchDist ead = new TblEmpAchDist();
		try {
			whereClause = " WHERE COMPANY='" + company + "'" +
			                  " AND EMPLOYEE='" + employeeNumber + "'" +
			                  " AND CHECK_ID='" + check_id + "'";
			sqlData = "SELECT * FROM " + data.getSchema() + "." + TABLE_NAME + (whereClause==null?"":whereClause);
			rslt = stmtData.executeQuery(sqlData);
			rsmd = rslt.getMetaData();
			if (rslt.next()){
				hasMoreRecs = true;
				ead = (TblEmpAchDist) createObject(rslt, ead);
			}
			else
				hasMoreRecs = false;
			return ead;
			//createFields(emp);
		} catch (SQLException e) {
		    // Could not connect to the database
			System.out.println("SQLException: " + e);
		} catch (InvocationTargetException ite) {
			System.out.println("InvocationException: " + ite);
		} catch (IllegalAccessException iae) {
			System.out.println("IllegalAccessException: " + iae);
		}
		return new TblEmpAchDist();
	}

	public boolean hasMore () {
	  return hasMoreRecs;
	}

		@Override
	public int countEmpAchDist() {
		try {
			countRecs = stmtData.executeQuery("SELECT COUNT(*) FROM " + data.getSchema() + "." + TABLE_NAME + (whereClause==null?"":whereClause));
			countRecs.next();
			return recCount=countRecs.getInt(1);
		} catch (SQLException e) {
		    // Could not connect to the database
			System.out.println("SQLException: " + e);
		}
		return 0;
	}
//
//	 private TblEmpAchDist createEmpAchDist(ResultSet rslt) throws SQLException, InvocationTargetException, IllegalAccessException,
//		IllegalArgumentException {
//		 TblEmpAchDist acd = new TblEmpAchDist();
//		Method[] mthds = acd.getClass().getMethods();
//		int i=0;
//		for(i=0;i<rsmd.getColumnCount();i++) {
//			if (rsmd.getColumnTypeName(i+1)=="CHAR") {
//				int j=0;
//				for(j=0;j<mthds.length;j++) {
//					if (mthds[j].getName().equalsIgnoreCase("set" + rsmd.getColumnName(i+1)))
//					{
//						mthds[j].invoke(acd, "\"" + rslt.getString(i+1).trim() + "\"");
//						//Get out of loop
//						j=mthds.length+1;
//					}
//				}
//			}
//			else if(rsmd.getColumnTypeName(i+1)=="NUMBER")
//				if(rsmd.getScale(i+1)==0) {
//					for(int j=0;j<mthds.length;j++) {
//						if (mthds[j].getName().equalsIgnoreCase("set" + rsmd.getColumnName(i+1)))
//						{
//							mthds[j].invoke(acd, rslt.getInt(i+1));
//							//Get out of loop
//							j=mthds.length+1;
//						}
//					}
//				}
//				else
//					for(int j=0;j<mthds.length;j++) {
//						if (mthds[j].getName().equalsIgnoreCase("set" + rsmd.getColumnName(i+1)))
//						{
//							mthds[j].invoke(acd, rslt.getFloat(i+1));
//							//Get out of loop
//							j=mthds.length+1;
//						}
//					}
//		}
//		return acd;
//	 }

	  private void init() throws SQLException, ClassNotFoundException, IOException {
		    // Set the data and xref variables
		    data = new DAOFactoryOracleDB();

		    sqlData = "SELECT * FROM " + data.getSchema() + "." + TABLE_NAME;
		    stmtData = data.getDataStatement();	    
		    countStmtData = data.getCountStatement();
		    //Set the Date Format for output
		    df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
	  }
}